from app import db
from datetime import datetime

class Exercise(db.Model):
    __tablename__ = 'exercises'
    
    id = db.Column(db.Integer, primary_key=True)
    user_id = db.Column(db.Integer, db.ForeignKey('users.id'), nullable=False)
    exercise_date = db.Column(db.Date, nullable=False)
    exercise_time = db.Column(db.Time, nullable=False)
    exercise_type = db.Column(db.String(50), nullable=False)  # 跑步、游泳、骑行等
    duration = db.Column(db.Integer, nullable=False)  # 运动时长(分钟)
    intensity = db.Column(db.String(20), nullable=False)  # 低强度、中强度、高强度
    calories_burned = db.Column(db.Integer)  # 消耗热量
    distance = db.Column(db.Float)  # 运动距离(公里)
    created_at = db.Column(db.DateTime, default=datetime.utcnow)
    note = db.Column(db.String(200))
    
    user = db.relationship('User', backref=db.backref('exercises', lazy='dynamic'))

    def __repr__(self):
        return f'<Exercise {self.exercise_type} on {self.exercise_date}>' 